<?php


/**
 * 遍历数组返回字串
 *
 */
function _for_str($arr,$val=''){
    $str = array();
    foreach($arr as $v){
        $str[]=$v['id'];
    }
    array_push($str,$val);
    return implode(',',$str);
}


//计算时间差
function getTime($sTime,$type='mohu'){
    if (!$sTime) return '';
    $cTime = time();
    $dTime = $cTime - $sTime;
    $dDay = intval(date("z", $cTime)) - intval(date("z", $sTime));
    $dYear = intval(date("Y", $cTime)) - intval(date("Y", $sTime));
    if($type == 'normal'){
        if($dTime < 60){
            if($dTime < 10){
                return '刚刚';
            }else{
                return intval(floor($dTime / 10) * 10) . "秒前";
            }
        }elseif($dTime < 3600){
            return intval($dTime / 60) . "分钟前";
        }elseif($dYear == 0 && $dDay == 0){
            return '今天' . date('H:i', $sTime);
        }elseif($dYear == 0){
            return date("m月d日 H:i", $sTime);
        }else{
            return date("Y-m-d H:i", $sTime);
        }
    }elseif($type == 'mohu'){
        if($dTime < 60){
            return $dTime . "秒前";
        }elseif($dTime < 3600){
            return intval($dTime / 60) . "分钟前";
        }elseif($dTime >= 3600 && $dDay == 0){
            return intval($dTime / 3600) . "小时前";
        }elseif($dDay > 0 && $dDay <= 7){
            return intval($dDay) . "天前";
        }elseif($dDay > 7 && $dDay <= 30){
            return intval($dDay / 7) . '周前';
        }elseif($dDay > 30){
            return intval($dDay / 30) . '个月前';
        }
    }elseif($type == 'full'){
        return date("Y-m-d , H:i:s", $sTime);
    }elseif($type == 'ymd'){
        return date("Y-m-d", $sTime);
    }else{
        if($dTime < 60){
            return $dTime . "秒前";
        }elseif($dTime < 3600){
            return intval($dTime / 60) . "分钟前";
        }elseif($dTime >= 3600 && $dDay == 0){
            return intval($dTime / 3600) . "小时前";
        }elseif($dYear == 0){
            return date("Y-m-d H:i:s", $sTime);
        }else{
            return date("Y-m-d H:i:s", $sTime);
        }
    }
}

/**
 * 获取未查询报价条数
 * @param $id
 */
function getOfferStatus($id){
    if(is_numeric($id)){
        return M('offer')->where(array('purchase_id'=>$id,'status'=>0))->count();
    }else{
        return 0;
    }
}
function scope($total, $t){
    if($total<3){
        return "低层";
    }
    $a = $total/3;
    if($t<=$a){
        return "低层";
    }
    if($t<=$a*2){
        return "中层";
    }else{
        return "高层";
    }
}